// var dao = require("./../dao/dao")
var clubInfo = require('./../class/club').getInstand;
var crypto = require('crypto');
var log = require("./../../util/loginfo").getInstand;

function makeDate(date) {

    try {

        var newDate = new Date(date);
        //在小于10的月份前补0  
        var month = eval(newDate.getMonth() + 1) < 10 ? '0' + eval(newDate.getMonth() + 1) : eval(newDate.getMonth() + 1);
        //在小于10的日期前补0  
        var day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate();
        //在小于10的小时前补0  
        var hours = newDate.getHours() < 10 ? '0' + newDate.getHours() : newDate.getHours();
        //在小于10的分钟前补0  
        var minutes = newDate.getMinutes() < 10 ? '0' + newDate.getMinutes() : newDate.getMinutes();
        //在小于10的秒数前补0  
        var seconds = newDate.getSeconds() < 10 ? '0' + newDate.getSeconds() : newDate.getSeconds();
        //拼接时间  
        var stringDate = newDate.getFullYear() + '-' + month + '-' + day + " " + hours + ":" + minutes + ":" + seconds;
    } catch (e) {
        var stringDate = "0000-00-00 00:00:00";
    } finally {
        return stringDate;
    }

};

function CheckDateTime(str) {
    var t1 = new Date(str).getTime();
    if (t1)
        return true;
    else
        return false;
}

var key = "dkl4234908fjfsn93d";


var api = function (req, callback) {
    var sendStr = '0';
    if (req.query.act == "tablequery") {


    } else if (req.query.act == "queryOnlineNum") {
        //验证md5
        var content = req.query.act + req.query.time + key;
        var md5 = crypto.createHash('md5');
        md5.update(content);
        if (md5.digest('hex') != req.query.sign) {
            sendStr = '{"status":0,"msg":"参数不正确!"}'
            callback(sendStr);
            return;
        }
        callback(JSON.stringify({status: 1, result: {online_num: clubInfo.getOnlinePlayerCount()}}));
    }
}


module.exports = api;